const { ccclass, property } = cc._decorator;

@ccclass
export default class game1000fish extends cc.Component {
    @property(cc.Node)
    comNode: cc.Node = null;
    value: number = 0;

    gamecom: any;
    movestate: boolean = false;
    protected onLoad(): void {
        this.gamecom = this.comNode.getComponent('game100')
    }

    fx: number = -1;
    data: any;
    initMgr() {
        this.fx = Math.random() > 0.5 ? 1 : -1
        if (this.fx == 1) {
            //左边生成，向右移动
            this.node.x = -500;
        } else if (this.fx == -1) {
            //右边生成，向左移动
            this.node.x = 500;
        }
        this.node.y = 400 - this.gamecom.content.height * Math.random();
        this.movestate = true;

        //设置分数大小
        let list = [
            { type: 0, bi: 0.5, value: 10, sudu: 2 },
            { type: 1, bi: 1, value: 30, sudu: 1 },
            { type: 2, bi: 1.5, value: 20, sudu: 0.7 },
        ]
        this.data = list[Math.floor(Math.random() * list.length)]
        this.value = this.data.value;
        this.node.width *= this.data.bi;
        this.node.height *= this.data.bi;
        this.node.getComponent(cc.BoxCollider).size = this.node.getContentSize();
    }

    protected update(dt: number): void {
        if (!this.movestate) { return; }
        let v = dt * 50 * this.data.sudu
        if (this.fx == -1) {
            this.node.x -= v;
            this.node.scaleX = 1;
        }
        if (this.fx == 1) {
            this.node.x += v;
            this.node.scaleX = -1;
        }
        if (this.node.x > 500) { this.fx = -1 }
        if (this.node.x < -500) { this.fx = 1 }
    }
}
